﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenPop.Pop3;
using OpenPop.Mime;

namespace Price_Tracker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a new list of messages to populate with emails from server
            List<OpenPop.Mime.Message> messages = new List<OpenPop.Mime.Message>();
            //New email instance
            OpenEmail email = new OpenEmail();
            //Only get the emails if there is connectivity
            if (email.checkConnectivity(hostTextBox.Text.Trim().ToString()))
            {
                messages = email.FetchAllMessages(hostTextBox.Text.ToString(), 995, true, usernameTextBox.Text.ToString(), passwordTextBox.Text.ToString());
   
            }
            if (!email.checkConnectivity(hostTextBox.Text.Trim().ToString()))
            {
                getEmailButton.Text = "Failed!";
            }
            //populate listbox with emails
            foreach (OpenPop.Mime.Message m in messages)
            {
                emailListBox.Items.Add(m.Headers.Subject.ToString());
            }
            
            //PriceTrackerEntities pte = new PriceTrackerEntities();
            //price_tracking_tbl pricetrack = new price_tracking_tbl();

            //emailList_tbl elt = new emailList_tbl();
            //elt.emailBody = 
 

        }

        private void emailListBox_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void hostTextBox_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
